Ext.define('cp.view.form.LicenciaBase',{
    extend: 'Ext.form.Panel',
   
    bodyPadding: '5px 5px 5px 5px', 
    bodyStyle: 'border: none',
    fieldDefaults: {
        labelWidth: 65,
        labelAlign: 'top'
    },
    
    initComponent: function(){
         this.action = this.actionUrl;
         
         var dsMedicos = Ext.create('cp.store.form.MedicoActivo',{});
         var dsLicencias = Ext.create('cp.store.form.TipoLicencia',{});
         var diaMin = new Date();
         
         var info = [
             { xtype: 'combo', name: 'medico', valueField: 'idUsuario', displayField: 'nombre',
               store: dsMedicos, allowBlank: false, fieldLabel: 'Médico' },
             { xtype: 'combo', name: 'licencia', valueField: 'idTipoLicencia', displayField: 'tipo',
               store: dsLicencias, allowBlank: false, fieldLabel: 'Licencia' },
             { fieldLabel:  'Fecha inicio', name: 'inicio', xtype: 'datefield',
              allowBlank: false, format: 'Y-m-d', minValue: diaMin },
             { fieldLabel:  'Fecha fin', name: 'fin', xtype: 'datefield',
              allowBlank: false, format: 'Y-m-d', minValue: diaMin }
         ];

         this.items = [
            {
                bodyStyle: 'border: none',
                layout: 'column',
                itemId: 'columnas',
                items: [
                    {
                        xtype: 'fieldset', defaultType: 'textfield', title: 'Licencia', 
                        layout: 'column', items:
                        [
                            {xtype: 'fieldset', defaultType: 'textfield', style: 'border: none',
                                items: info}
                        ]
                    }
              ]
            }
         ];
         
         this.callParent(arguments)
         
    },
    submitForm: function(){
        if(this.getForm().isValid()){
            this.sendData();
        }else{
            Ext.create('cp.view.ui.AlertErr',{
                mensaje: 'El formulario contiene errores. Por favor, corrigalos, y vuelva a realizar la operación.'
                    }).showDialog();    
        }
    },
    sendData: function(){
        var me = this;
        this.getForm().submit({
            url: me.action,
            method: 'POST',
            success: function(form,action){
                Ext.create('cp.view.ui.AlertOk',{mensaje:action.result.msg}).showDialog();
                me.up('decoratorForm').close();
                Ext.ComponentQuery.query('gestionLicencia')[0].getStore().load();                 
            },
            failure: function(form, action){
                Ext.create('cp.view.ui.AlertErr',{mensaje:action.result.msg}).showDialog();
            }
        });
    }
});